#include<bits/stdc++.h>
#define int long long
#define N 300005
using namespace std;
int n,q;
int l[N],r[N];
void sub(){
	while(q--){
		int o,a,b,c,d;
		scanf("%lld %lld %lld %lld",&o,&a,&b,&c);
		if(o==1) l[a]=b,r[a]=c;
		else{
			scanf("%lld",&d);
			int ans=0;
			if(a<=c){
				for(int i=a;i<c;i++){
					if(b<l[i]) b=l[i];
					else if(b>=r[i]) ans+=(b-r[i]+1),b=r[i]-1;
					b++;
				}
				if(b>d) ans+=b-d;
				printf("%lld\n",ans);
			}
			else{
				for(int i=a-1;i>=c;i--){
					if(b<l[i]) b=l[i];
					else if(b>=r[i]) ans+=(b-r[i]+1),b=r[i]-1;
					b++;
				}
				if(b>d) ans+=b-d;
				printf("%lld\n",ans);
			}
		}
	}
}
signed main(){
	freopen("study.in","r",stdin);
	freopen("study.out","w",stdout);
	scanf("%lld %lld",&n,&q);
	for(int i=1;i<n;i++) scanf("%lld %lld",&l[i],&r[i]);
	sub();
	return 0;
}